package com.genericdao.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.genericdao.intf.BaseDao;
import com.genericdao.intf.BaseService;

/**
 * 业务层基类，被具体业务组件继承
 * @author lin
 *
 * @param <T>
 */
public class BaseServiceImpl<T> implements BaseService<T> {
	
	/**
	 * 注入dao
	 */
	private BaseDao<T> baseDao;

	public BaseDao<T> getBaseDao() {
		return baseDao;
	}

	public void setBaseDao(BaseDao<T> baseDao) {
		this.baseDao = baseDao;
	}

	@Override
	public void add(T t) {
		
		if(t != null)
		{
			baseDao.create(t);
		}
		
	}

	@Override
	public void delete(Integer id) {
		
		if(id != null)
		{
			baseDao.delete(id);
		}
		
	}

	@Override
	public void update(T t) {
		
		if(t != null)
		{
			baseDao.update(t);
		}
		
	}

	@Override
	public T get(Integer id) {
		
		if(id != null)
		{
			return baseDao.read(id);
		}
		
		return null;
	}

	@Override
	public List<T> getAll() {
		
		return baseDao.listAll();
	}

	@Override
	public List<T> getAll(String hqlExpression, Object... parameters) {
		
		return baseDao.listAll(hqlExpression, parameters);
	}

}
